package zero.tech.games.jh.event;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.event.EventListener;
import zero.tech.core.event.EventType;
import zero.tech.games.jh.data.JhConfig;
import zero.tech.games.jh.data.JhGameBase;
import zero.tech.games.jh.data.JhRoomCache;
import zero.tech.games.jh.data.JhTimer;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;

public class RoomCreated implements EventListener{

	@Override
	public EventType netEventType() {
		return LogicEventType.ROOM_CREATED;
	}

	@Override
	public void notifyEvent(Object... objs) {
		Room room = (Room) objs[0];
		JhTimer jhTimer=new JhTimer(room.getRoom_id());
		room.setTimer(jhTimer);
		JhRoomCache jhRoomCache=new JhRoomCache(room.getRoom_id());
		room.setRoomCache(jhRoomCache);
		JhConfig jhConfig=JSONObject.parseObject(room.getConfigStr(),JhConfig.class);
		room.setGameConfig(jhConfig);
		JhGameBase jhGameBase=new JhGameBase(room.getRoom_id());
		room.setGameBase(jhGameBase);
	}

	@Override
	public boolean asynchronous() {
		return false;
	}

}
